﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace Black.SurfaceToolkit.Effects
{
    /// <summary>
    /// GloomEffect Effect
    /// </summary>
    public class GloomEffect : ShaderEffect
    {
        #region Propriétées de dépendances

        public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(GloomEffect), 0);
        public static readonly DependencyProperty GloomIntensityProperty = DependencyProperty.Register("GloomIntensity", typeof(double), typeof(GloomEffect), new UIPropertyMetadata(1.0, ShaderEffect.PixelShaderConstantCallback(0)));
        public static readonly DependencyProperty BaseIntensityProperty = DependencyProperty.Register("BaseIntensity", typeof(double), typeof(GloomEffect), new UIPropertyMetadata(1.0, ShaderEffect.PixelShaderConstantCallback(1)));
        public static readonly DependencyProperty GloomSaturationProperty = DependencyProperty.Register("GloomSaturation", typeof(double), typeof(GloomEffect), new UIPropertyMetadata(1.0, ShaderEffect.PixelShaderConstantCallback(2)));
        public static readonly DependencyProperty BaseSaturationProperty = DependencyProperty.Register("BaseSaturation", typeof(double), typeof(GloomEffect), new UIPropertyMetadata(1.0, ShaderEffect.PixelShaderConstantCallback(3)));

        #endregion

        #region Accesseurs

        /// <summary>
        /// Affecte ou retourne la propriété Input du Shader
        /// </summary>
        [System.ComponentModel.BrowsableAttribute(false)]
        public Brush Input
        {
            get
            {
                return ((Brush)this.GetValue(GloomEffect.InputProperty));
            }
            set
            {
                this.SetValue(GloomEffect.InputProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété GloomIntensity du Shader
        /// </summary>
        public double GloomIntensity
        {
            get
            {
                return ((double)this.GetValue(GloomEffect.GloomIntensityProperty));
            }
            set
            {
                this.SetValue(GloomEffect.GloomIntensityProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété BaseIntensity du Shader
        /// </summary>
        public double BaseIntensity
        {
            get
            {
                return ((double)this.GetValue(GloomEffect.BaseIntensityProperty));
            }
            set
            {
                this.SetValue(GloomEffect.BaseIntensityProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété GloomSaturation du Shader
        /// </summary>
        public double GloomSaturation
        {
            get
            {
                return ((double)this.GetValue(GloomEffect.GloomSaturationProperty));
            }
            set
            {
                this.SetValue(GloomEffect.GloomSaturationProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété BaseSaturation du Shader
        /// </summary>
        public double BaseSaturation
        {
            get
            {
                return ((double)this.GetValue(GloomEffect.BaseSaturationProperty));
            }
            set
            {
                this.SetValue(GloomEffect.BaseSaturationProperty, value);
            }
        }

        #endregion

        #region Variables statiques

        private static readonly PixelShader _PixelShader = new PixelShader();

        #endregion

        #region Constructeurs

        /// <summary>
        /// Constructeur statique
        /// </summary>
        static GloomEffect()
        {
            GloomEffect._PixelShader.UriSource = new Uri("pack://application:,,,/Black.SurfaceToolkit;component/Effects/Shaders/Gloom.ps");
        }

        /// <summary>
        /// Constructeur de la classe
        /// </summary>
        public GloomEffect()
        {
            this.PixelShader = GloomEffect._PixelShader;

            this.UpdateShaderValue(GloomEffect.InputProperty);
            this.UpdateShaderValue(GloomEffect.GloomIntensityProperty);
            this.UpdateShaderValue(GloomEffect.BaseIntensityProperty);
            this.UpdateShaderValue(GloomEffect.GloomSaturationProperty);
            this.UpdateShaderValue(GloomEffect.BaseSaturationProperty);
        }

        #endregion
    }
}
